import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';

import '../../../public_util.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    IntegralExchangeState state, Dispatch dispatch, ViewService viewService) {
  double cellWidth = ((MediaQuery.of(viewService.context).size.width - 30 - 7) / 2);
  double desiredCellHeight = cellWidth + setWidth(8) + setWidth(17) + setWidth(25) + setWidth(25) + setWidth(10);
  double childAspectRatio = cellWidth / desiredCellHeight;
  return Scaffold(
    backgroundColor: Color.fromRGBO(248, 248, 248, 1),
    appBar: AppBar(
      title: Text(
        '积分兑好礼',
        style: TextStyle(
            color: Color.fromRGBO(47, 47, 47, 1),
            fontSize: setSp(16),
            fontWeight: FontWeight.bold),
      ),
      leading: GestureDetector(
          onTap: () {
            Navigator.pop(viewService.context);
          },
          child: Icon(Icons.arrow_back_ios_rounded,
              color: Color.fromRGBO(47, 47, 47, 1))),
      centerTitle: true,
      backgroundColor: Colors.white,
      elevation: 0.0,
      brightness: Brightness.light,
    ),
    body: Container(
      margin: EdgeInsets.only(left: setWidth(15),right: setWidth(15),bottom: setWidth(10),),
      child: CustomScrollView(
      slivers: <Widget>[
        SliverList(
          delegate: SliverChildListDelegate(
            [
              Container(
                margin: EdgeInsets.fromLTRB(0, setWidth(15),0, setWidth(10)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child: Text(
                        '全部礼品',
                        style: TextStyle(
                          fontSize: setSp(16),
                          color: Color.fromRGBO(47, 47, 47, 1),
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                      //  Navigator.pushNamed(viewService.context, '');
                      },
                      child: Row(
                        children: [
                          Text(
                            "兑换记录 ",
                            style: TextStyle(
                              color: Color.fromRGBO(47, 47, 47, 1),
                              fontSize: setSp(12),
                            ),
                          ),
                          Image.asset(
                            'assets/images/user_center/task_sign_right.png',
                            width: setWidth(8),
                            height: setWidth(8),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
          SliverGrid(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              childAspectRatio: childAspectRatio,
              mainAxisSpacing: 10,
              crossAxisSpacing: 7,
            ),

            delegate:  SliverChildBuilderDelegate(
                  (BuildContext context, num index) {
                return Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(setWidth(10)),),
                    color: Colors.white,
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(setWidth(10)), topRight: Radius.circular(setWidth(10))),
                        child: Image.network(
                          index % 2 == 0
                              ? "https://img.gzzhitu.com/zhitu-api/1622894340675195.jpg"
                              : "https://img.gzzhitu.com/zhitu-api/1622894340689970.jpg",
                          height: cellWidth,
                          width: cellWidth,
                          fit: BoxFit.cover,
                        ),
                      ),
                      SizedBox(
                        height: setWidth(8),
                      ),
                      Container(
                        height: setWidth(17),
                        padding: EdgeInsets.symmetric(horizontal: setWidth(8)),
                        child: Text('光明 优加纯牛奶250ml*16盒/礼盒装 中华老字号光明',
                                style: TextStyle(
                                  color: Color.fromRGBO(47, 47, 47, 1),
                                  fontSize: setSp(12),
                                  fontWeight: FontWeight.bold,
                                ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      SizedBox(
                        height: setWidth(25),
                      ),
                      Container(
                        height: setWidth(25),
                        padding: EdgeInsets.symmetric(horizontal: setWidth(8)),
                      //  margin: EdgeInsets.only(bottom:setWidth(10)),
                        child: Row(
                          children: [
                            Image.asset(
                              'assets/images/user_center/task_sign_im.png',
                              width: setWidth(14),
                              height: setWidth(14),
                            ),
                            SizedBox(
                              width: setWidth(3),
                            ),
                            Expanded(
                              child:
                              Text.rich(
                                TextSpan(
                                  children: [
                                    TextSpan(
                                      text: "8000 ",
                                      style: TextStyle(
                                        color: Color.fromRGBO(255, 37, 38, 1),
                                        fontSize: setSp(14),
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                    TextSpan(
                                      text: '￥19.8',
                                      style: TextStyle(
                                        color: Color.fromRGBO(177, 178, 186, 1),
                                        fontSize: setSp(11),
                                        decoration: TextDecoration.lineThrough,
                                        decorationColor: Color.fromRGBO(177, 178, 186, 1),
                                      ),
                                    ),
                                  ],
                                ),
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                            InkWell(
                              onTap: () {
                                Navigator.pushNamed(viewService.context, 'exchange_detail');
                              },
                              child: Container(
                                width: setWidth(40),
                                height: setWidth(25),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  gradient: LinearGradient(colors: [
                                    Color.fromRGBO(252, 132, 37, 1),
                                    Color.fromRGBO(255, 89, 64, 1)
                                  ]),
                                  borderRadius: BorderRadius.circular(setWidth(25)),
                                ),
                                child: Text(
                                  '兑换',
                                  style: TextStyle(
                                    fontSize: setSp(12),
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                );
              },
              ///子Item的个数
              childCount: 20,
            ),
          ),
      ],
    ),
  ),);
}
